package cn.dy.sbo.core;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;

import cn.common.lib.springside.orm.BaseDao;
import cn.common.lib.springside.orm.ExtPropertyFilter;
import cn.common.lib.springside.service.EntityManager;
import cn.dy.sbo.api.DraftOrdersDao;
import cn.dy.sbo.api.OrdersDao;
import cn.dy.sbo.contants.Constants;
import cn.dy.sbo.model.DraftOrders;
import cn.dy.sbo.model.Orders;

@Component
@Transactional
public class DraftOrdersManager extends EntityManager<DraftOrders, Long>{

	@Autowired
    private DraftOrdersDao draftOrdersDao;
	
	@Autowired
    private OrdersDao ordersDao;
	
	@Override
	protected BaseDao<DraftOrders, Long> getEntityDao() {
		return draftOrdersDao;
	}
	public Page<DraftOrders> extSearch(Page<DraftOrders> page,
			List<ExtPropertyFilter> filters) {
		return draftOrdersDao.extFindPage(page, filters);
	}
	public void tosbo(List<Long> ids) {
		for(long id:ids){
			DraftOrders d = this.get(id);
			d.setStatus(Constants.DRAFT_STATUS_ACTIVE);
			d.setSys("SAP");
			this.save(d);
		}
	}
	
	public void totms(List<Long> ids) {
		for(long id:ids){
			DraftOrders d = this.get(id);
			d.setStatus(Constants.DRAFT_STATUS_ACTIVE);
			d.setSys("TMS");
			this.save(d);
			Orders order = new Orders();
			BeanUtils.copyProperties(d, order,new String[]{"id","status"});
			ordersDao.save(order);
			
		}
	}

}
